//
//  Message.m
//  ChatDemo
//
//  Created by 陈石 on 15/5/13.
//  Copyright (c) 2015年 陈石. All rights reserved.
//

#import "Message.h"
#import "NSDate+Local.h"

@implementation Message

- (void)SetMsgWithDict:(NSDictionary *)dict MessageFrom:(MessageFrom)from
{
    if (dict[@"fromContact"][@"thumbnailURL"] != [NSNull null])
    {
        self.strIcon = [dict[@"fromContact"] objectForKey:@"thumbnailURL"];
    }
    else
    {
        self.strIcon = @"";
    }

    self.strId   = [dict[@"fromContact"] objectForKey:@"id"];
    self.strName = [dict[@"fromContact"] objectForKey:@"alias"];
    self.strTime = [[NSDate dateFromJSONString:[dict objectForKey:@"modifiedDate"]] datePassedDesc];
    self.from    = from;

    [self SetContent:dict];
}

- (void)SetContent:(NSDictionary *)dict
{
    if ([dict[@"messageType"] isEqualToString:@"Text"])
    {
        self.type       = MessageTypeText;
        self.strContent = dict[@"message"];
    }
    if ([dict[@"messageType"] isEqualToString:@"Image"])
    {
        self.type       = MessageTypePicture;
        self.pictureURL = dict[@"imageURL"];
    }
    if ([dict[@"messageType"] isEqualToString:@"Audio"])
    {
        self.type     = MessageTypeVoice;
        self.voiceURL = dict[@"audioURL"];
        //self.strVoiceTime = dict[@"strVoiceTime"];
    }
}

@end
